package com.hs.ph.dao.impl;

import com.hs.ph.dao.UserDao;
import com.hs.ph.entity.User;
import com.hs.ph.utitl.JDBCDruidUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    @Override
    public User SelectByUsernameAndPwd(String username, String pwd) {
        User user=null;
        String sql="select * from user where username=? and pwd=?";
        Object[] obj={username,pwd};
        ResultSet res = JDBCDruidUtil.query(sql, obj);
        while (true) {
            try {
                if (!res.next()) break;
                user=new User(res.getInt(1),
                        res.getString(2),
                        res.getString(3));
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        return user;
    }
}
